package com.loren.demo24.service;

import com.loren.demo24.form.DemoForm;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
@AllArgsConstructor
public class DemoService {

    private final JdbcTemplate jdbcTemplate;

    @Transactional
    public List<Map<String, Object>> demo01(DemoForm demoForm) {
        log.info("demoForm = {}", demoForm);
        String insertSQL = "insert into sys_task (name, test_date1, test_date2) values (?, ?, ?)";
        this.jdbcTemplate.update(insertSQL, demoForm.getName(), demoForm.getTestDate1(), demoForm.getTestDate2());
        List<Map<String, Object>> mapList = this.jdbcTemplate.queryForList("select * from sys_task");
        System.out.println(mapList.size());
        log.info("mapList.size = {}", mapList.size());
        return mapList;
    }
}
